import {
  editUserInfo
} from "../../apis/user";
const app = getApp();

Page({
  data: {

  },

  onLoad() {
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          app.globalData.isAuthorize = true;
          let timer = setTimeout(() => {
            wx.switchTab({
              url: '/pages/mailList/index'
            });
            clearTimeout(timer);
          }, 1000);
        };
      }
    });
  },

  onShareAppMessage() {
    return {
      title: '快闪名片',
      path: '/pages/start/index',
      imageUrl: ''
    }
  },

  bindgetuserinfo(e) {
    if (e.detail.userInfo) {
      app.globalData.isAuthorize = true;
      this.editUserInfo(e.detail.userInfo.nickName, e.detail.userInfo.avatarUrl, e.detail.userInfo.gender);
    } else {
      app.globalData.isAuthorize = false;
    };
    wx.switchTab({
      url: '/pages/mailList/index'
    });
  },

  editUserInfo(nickname, avatar, sex) {
    editUserInfo({
      nickname,
      avatar,
      sex
    }).then();
  }
})